import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
// import vuexPersist from "vuex-persist"; //持久化插件
import { getLogin } from "@/api/api.js"

export default new Vuex.Store({
  state: {
     token:'',
  },
  mutations: {
    setLogin(state,token){
      state.token=token
      localStorage.setItem('token',token)
    }
  },
  actions: {
    //异步操作
    // setLogin({commit},user){
    //   console.log('接收信息',user)
    //   getLogin(user).then(res=>{
    //     console.log('登录成功的结果',res)
    //     commit('setLogin',res.data.token)
    //     if(res.meta.status==200)
    //       location.href='/#/home'
    //     }
    //   })
    // }
  },
  getters:{},
  modules: {},
  // plugins: [
  //   new vuexPersist({
  //     localstorage: window.localStorage,
  //   }).plugin,
  // ],
});
